<template>
  <div>

      <form action="">
        <div>用户名：<input type="text" v-model="username" /></div>
        <div>密码：<input type="password" v-model="password" /></div>
        <button @click="login">登录</button>
        <p style="color:red">{{errorMessage}}</p>
      </form>
  </div>
</template>

<script>
export default
 {
   name:'Login',
      data ()
      {
        return{
           username :'',
           password :'',
           errorMessage : ''

  }
      },

 methods:{
   login(){
    this.axios.post("http://127.0.0.1:8081/login",{
      username: this.username,
      password:this.password

    }).then(response=>{

      console.log(response)
     if(response.data.success==true){
       this.$router.push('/home');
     }
     else{
       this.errorMessage = response.data.msg;

     }
    }).catch(error=>{
      console.log(error);
    })
     
   }
 }

}
</script>

<style>

</style>